package com.cloudcc.mobile.view.fragment;

import java.io.Serializable;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.Bind;
import butterknife.OnClick;

import com.cloudcc.cloudframe.bus.EventEngine;
import com.cloudcc.cloudframe.bus.IEventLife;
import com.cloudcc.cloudframe.net.ErrorInfo;
import com.cloudcc.cloudframe.net.RequestListener;
import com.cloudcc.cloudframe.ui.viewgroup.loadmore.LoadMoreContainer;
import com.cloudcc.cloudframe.ui.viewgroup.loadmore.LoadMoreHandler;
import com.cloudcc.cloudframe.ui.viewgroup.refresh.PtrDefaultHandler;
import com.cloudcc.cloudframe.ui.viewgroup.refresh.PtrFrameLayout;
import com.cloudcc.cloudframe.ui.viewgroup.refresh.PtrHandler;
import com.cloudcc.cloudframe.util.ListUtils;
import com.cloudcc.cloudframe.util.StringUtils;
import com.cloudcc.mobile.AppContext;
import com.cloudcc.mobile.ExtraConstant;
import com.cloudcc.mobile.R;
import com.cloudcc.mobile.ReceiverConstant;
import com.cloudcc.mobile.adapter.BeauFilterChildAdapter;
import com.cloudcc.mobile.adapter.BeauFilterChildAdapter.OnSelectItemListener;
import com.cloudcc.mobile.adapter.BeauFilterParentAdapter;
import com.cloudcc.mobile.adapter.BeauFilterParentAdapter.OnItemSelectListener;
import com.cloudcc.mobile.adapter.BeauListAdapter;
import com.cloudcc.mobile.adapter.BeauListAdapter.OnClickItem;
import com.cloudcc.mobile.adapter.BeauListAdapter.onItemMenuClickListener;
import com.cloudcc.mobile.adapter.BeauShiTuAdapter;
import com.cloudcc.mobile.entity.beau.BeauListEntity;
import com.cloudcc.mobile.entity.beau.BeauListFilterEntity;
import com.cloudcc.mobile.entity.beau.BeauListFilterEntity.SearchFilter;
import com.cloudcc.mobile.entity.beau.BeauListFilterEntity.SearchFilter.FilterChild;
import com.cloudcc.mobile.entity.beau.BeauListFilterEntity.SearchView;
import com.cloudcc.mobile.event.BeauEventList.BeauListEvent;
import com.cloudcc.mobile.event.BeauEventList.BeauListFilterEvent;
import com.cloudcc.mobile.event.refresh.RefreshEntiityListEvent;
import com.cloudcc.mobile.manager.UrlManager;
import com.cloudcc.mobile.presenter.BeauPresenter;
import com.cloudcc.mobile.presenter.BeauPresenter.FilterCondition;
import com.cloudcc.mobile.presenter.OtherPresenter;
import com.cloudcc.mobile.util.PopuWindowUtils;
import com.cloudcc.mobile.util.SystemUtils;
import com.cloudcc.mobile.util.ViewUtils;
import com.cloudcc.mobile.view.activity.BeauInfoActivity;
import com.cloudcc.mobile.view.activity.BeauSortActivity;
import com.cloudcc.mobile.view.main.fragment.BaseListFragment;
import com.cloudcc.mobile.view.web.CloudWebViewActivity;
import com.cloudcc.mobile.view.web.WebSyncDefaultProxy;
import com.cloudcc.mobile.view.web.WebSyncDefaultProxy.MonitorParam;
import com.cloudcc.mobile.weight.viewgroup.SoftKeyboardHandledLinearLayout;
import com.cloudcc.mobile.weight.viewgroup.SoftKeyboardHandledLinearLayout.SoftKeyboardVisibilityChangeListener;
import com.cloudcc.mobile.widget.listview.CloudCCListView;
import com.cloudcc.mobile.widget.listview.CloudCCListView.OnRefreshOrLoadMoreListener;
import com.daimajia.androidanimations.library.Techniques;
import com.daimajia.androidanimations.library.YoYo;
import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.Animator.AnimatorListener;

public class BeauListFragment extends BaseListFragment implements 
		 IEventLife, onItemMenuClickListener, OnClickItem,
		SoftKeyboardVisibilityChangeListener, OnRefreshOrLoadMoreListener {
	@Bind(R.id.testsss)
	CloudCCListView mListView;



	@Bind(R.id.container1)
	RelativeLayout rlButtom;

	@Bind(R.id.et_search_content)
	EditText mSearchContent;

	@Bind(R.id.ll_searchparent)
	LinearLayout ll_searchparent;

	@Bind(R.id.container)
	SoftKeyboardHandledLinearLayout container;

	private PopupWindow mSearchView;

	private BeauPresenter mBeauPresenter = new BeauPresenter();

	private BeauListAdapter mAdapter;

	private int[] mFilterSelectArray;
	/**
	 * 是否是第一次请求 如果是第一次请求 就 先请求 筛选条件
	 */
	private boolean isFristRequest = true;
	/**
	 * 过滤器数据
	 */
	private BeauListFilterEntity mFilter;

	private boolean isShowShiTuView;

	private FilterCondition mFilterCondition = null;

	
	@Override
	public void init() {
		register();
		initHeader();
		mFilterCondition = new FilterCondition();
		mListView.getLoadMore().setOnScrollListener(mScrollListener);
		mListView.setOnRefreshOrLoadMoreListener(this);
		mListView.requestRefresh();
		mSearchContent.setOnFocusChangeListener(new OnFocusChangeListener() {
			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				if (hasFocus) {
					showShiTuView();
				}
			}
		});
		mSearchContent.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				showShiTuView();
			}
		});

		container.setOnSoftKeyboardVisibilityChangeListener(this);

		initReceiver();
		
		initEdit();
	}



	private void initEdit() {
		mSearchContent
		.setOnEditorActionListener(new EditText.OnEditorActionListener() {

			@Override
			public boolean onEditorAction(TextView v, int actionId,
					KeyEvent event) {
				if (actionId == EditorInfo.IME_ACTION_SEARCH) {
					InputMethodManager imm = (InputMethodManager) v
							.getContext().getSystemService(
									Context.INPUT_METHOD_SERVICE);
					imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
					clickSearch();
					return true;
				}
				return false;
			}

		});
		
	}



	private void initHeader() {
		Bundle bundle = getArguments();
		if (bundle != null) {
			mEntityName = bundle.getString(ExtraConstant.EXTRA_NAME, "对象列表");
			mEntityId = bundle.getString(ExtraConstant.EXTRA_ID, "");
			mNewUrl = bundle.getString(ExtraConstant.EXTRA_URL, "");
		}
		((TextView) findViewById(R.id.header_title)).setText(mEntityName);
		((TextView) findViewById(R.id.header_right)).setText("新建");
	}

	private boolean scrollFlag = false;// 标记是否滑动
	private int lastVisibleItemPosition = 0;// 标记上次滑动位置
	private OnScrollListener mScrollListener = new OnScrollListener() {
		@Override
		public void onScrollStateChanged(AbsListView view, int scrollState) {
			switch (scrollState) {
			case OnScrollListener.SCROLL_STATE_IDLE:// 屏幕停止滚动的时候
				scrollFlag = false;
				break;
			case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:// 滚动时
				if (mAdapter != null) {
					mAdapter.resetMenu();
				}
				scrollFlag = true;
				break;
			case OnScrollListener.SCROLL_STATE_FLING:// 是当用户由于之前划动屏幕并抬起手指，屏幕产生惯性滑动时
				scrollFlag = false;
				break;
			default:
				break;
			}
		}

		@Override
		public void onScroll(AbsListView view, int firstVisibleItem,
				int visibleItemCount, int totalItemCount) {
			if (scrollFlag) {
				if (firstVisibleItem > lastVisibleItemPosition
						|| currentPage == 1) {// 上滑
					hideToolbar();
				} else if (firstVisibleItem < lastVisibleItemPosition) {// 下滑
					showToolbar();
				} else {
					return;
				}
				lastVisibleItemPosition = firstVisibleItem;
			}
		}
	};

	@OnClick(R.id.search)
	public void clickSearch() {
		InputMethodManager imm = (InputMethodManager) mContext
				.getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(mSearchContent.getWindowToken(), 0);
		mListView.requestRefresh();
	}

	private String mEntityName = "对象列表";
	private String mEntityId;
	private String mNewUrl;

	/**
	 * 刷新服务器的菜单列表
	 */
	private void requestFilter() {
		mBeauPresenter.getBeanFilter(mEntityId);
	}

	@OnClick(R.id.back)
	public void clickback() {
		getActivity().finish();
	}

	/**
	 * 显示 视图标签
	 */
	private int mShiTuSelectPos = 0;

	private void showShiTuView() {
		if (isShowShiTuView) {
			return;
		}
		if (!hasShiTuViewData()) {
			showNoFilterToast();
			requestFilter();
			return;
		}
		// 存在数据
		PopuWindowUtils.dissmiss(mSearchView);
		View contentView = (View) View.inflate(mContext,
				R.layout.beau_search_shitu, null);
		ListView listView = (ListView) contentView.findViewById(R.id.listview2);
		BeauShiTuAdapter adapter = new BeauShiTuAdapter(mContext);
		listView.setAdapter(adapter);
		adapter.changeData(mFilter.search_view);
		adapter.setSelectItem(mShiTuSelectPos);
		adapter.setmOnSelectItemListener(new BeauShiTuAdapter.OnSelectItemListener() {
			@Override
			public void onSelectItem(int pos, SearchView t) {
				mShiTuSelectPos = pos;
				mListView.requestRefresh();
				PopuWindowUtils.dissmiss(mSearchView);
			}
		});
		//测量listview
		int totalHeightofListView = ViewUtils.getTotalHeightofListView(listView);
		mSearchView = new PopupWindow(contentView, ll_searchparent.getWidth(),
				Math.min(AppContext.screenH / 3, totalHeightofListView));
		mSearchView.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
		mSearchView.setFocusable(false);
		mSearchView.setOnDismissListener(new OnDismissListener() {
			@Override
			public void onDismiss() {
				isShowShiTuView = false;
			}
		});
		mSearchView.showAsDropDown(ll_searchparent);

	}

	@Override
	public void requestData() {
		// 取消 视图 popuwindow
		PopuWindowUtils.dissmiss(mSearchView);
		// 获取 检索条件
		if (mFilter == null) {
			return;
		}
		mFilterCondition.pageNum = currentPage;
		if (mFilter.search_filter != null) {
			for (int i = 0; i < mFilter.search_filter.size(); i++) {
				SearchFilter searchFilter = mFilter.search_filter.get(i);
				if (mFilterSelectArray[i] != -1) {
					FilterChild filterChild = searchFilter.values
							.get(mFilterSelectArray[i]);
					mFilterCondition.filterFileds.put(searchFilter.name,
							filterChild.name);
				}
			}
		}
		// 视图
		if (!ListUtils.isEmpty(mFilter.search_view)) {
			try {
				SearchView searchView = mFilter.search_view
						.get(mShiTuSelectPos);
				mFilterCondition.viewId = searchView.id;
			} catch (Exception e) {
				SearchView searchView = mFilter.search_view.get(0);
				mFilterCondition.viewId = searchView.id;
			}
		}
		// 排序

		// 关键字
		mFilterCondition.keyword = mSearchContent.getText().toString();

		mBeauPresenter.getBeanList(mFilterCondition);
	}


	@OnClick(R.id.beau_bottom_filter)
	public void clickFilter() {
		showFilterView();
	}

	@OnClick(R.id.beau_bottom_sort)
	public void clickSort() {
		if (!hasSortViewData()) {
			showNoFilterToast();
			return;
		}
		Intent intent = new Intent(mContext, BeauSortActivity.class);
		intent.putExtra("sort.filter", (Serializable) mFilter.search_sort);
		intent.putExtra("sort.name", mFilterCondition.sortFiled);
		intent.putExtra("sort.asc", mFilterCondition.sorModel);
		intent.putExtra("sort.title", mEntityName);
		intent.putExtra("sort.nameid", mEntityId);
		startActivityForResult(intent, 1001);
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		if (resultCode == Activity.RESULT_OK && requestCode == 1001) {
			mFilterCondition.sortFiled = data.getStringExtra("sort.name");
			mFilterCondition.sorModel = data.getBooleanExtra("sort.asc", true);
			mListView.requestRefresh();
		}
	}

	@Override
	public int getLayoutId() {
		return R.layout.beau_list_frag;
	}

	private void refresh(){
		if (isFristRequest) {// 如果 mfilter空的话 先获取 筛选条件
			requestFilter();
		} else {
			onRefreshData();
		}
	}

	/**
	 * 加载到数据
	 * 
	 * @param event
	 */
	public void onEventMainThread(BeauListEvent event) {

		if ((event.isError() && isFromRefresh())
				|| ListUtils.isEmpty(event.getData()) && isFromRefresh()) {
			mListView.empty();
		}
		if (event.isError()) {
			if (isFromRefresh()) {
				mListView.refreshComplete();
				mListView.handlerLoadMoreFinish(true, false);
			} else {
				mListView.handlerLoadMoreError(1002, event.getMessage());
			}
			Toast.makeText(mContext, event.getMessage(), 0).show();
			return;
		}
		onRequestFinish(ListUtils.isEmpty(event.getData()));
		if (mAdapter == null) {
			mAdapter = new BeauListAdapter(mContext);
			mAdapter.setOnItemMenuClickListener(this);
			mListView.setAdapter(mAdapter);
			mAdapter.setmOnClickItem(this);
		}
		if (isFromRefresh()) {
			mAdapter.changeData(event.getData());
		} else {
			mAdapter.addData(event.getData());
		}
	}
	
	/**  检测是否取消关注
	 * @param evnet
	 */
	public void onEventMainThread(RefreshEntiityListEvent evnet){
		if (!evnet.isOk()) {
			return;
		}
		String[] data = evnet.getData();
		for (BeauListEntity entity : mAdapter.getData()) {
			if (StringUtils.equals(entity.getId(),data[0])) {
				entity.ismefollow =Boolean.valueOf(data[1]);
				break;
			}
		}
		mAdapter.notifyDataSetChanged();
	}

	/**
	 * 获取 beau筛选成功
	 * 
	 * @param event
	 */
	public void onEventMainThread(BeauListFilterEvent event) {
		if (event.isError()) {
			mListView.refreshComplete();
			mListView.empty();
			// mLoadMoreLayout.loadMoreError(1002, event.getMessage());
			Toast.makeText(mContext, event.getMessage(), 0).show();
			return;
		}
		this.mFilter = event.getData();

		refreshFilterData();
		// 判断 是否 先 刷新
		//
		if (isFristRequest) {
			isFristRequest = false;
			onRefreshData();
		}

	}

	/**
	 * 刷新筛选期的将要使用的数据
	 */
	private void refreshFilterData() {
		if (mFilter == null) {
			return;
		}
		if (!ListUtils.isEmpty(mFilter.search_filter)) {
			mFilterSelectArray = new int[mFilter.search_filter.size()];
			for (int i = 0; i < mFilterSelectArray.length; i++) {
				mFilterSelectArray[i] = -1;
			}
		}
		if (!ListUtils.isEmpty(mFilter.search_view)) {
			for (int i=0;i<mFilter.search_view.size();i++) {
				if (TextUtils.equals(mFilter.search_view.get(i).isdefault, "1")) {
					mShiTuSelectPos =i;
				}
			}
		}
	}

	private void onRequestFinish(boolean dataIsEmpty) {
		if (isFromRefresh()) {// 第一次加载 并且数据出现空的话 就显示 空
			mListView.refreshComplete();
			mListView.handlerLoadMoreFinish(dataIsEmpty, !dataIsEmpty);// 第一次加载
		} else {
			mListView.refreshComplete();
			mListView.handlerLoadMoreFinish(false, !dataIsEmpty);// 不是来自刷新 是来自
																// 上啦加载更多 这样的话
		}
	}

	/**
	 * 显示工具栏
	 */
	private void showToolbar() {
		PopuWindowUtils.dissmiss(mSearchView);
		if (rlButtom.getVisibility() == View.GONE
				&& !container.isKeyboardShown()) {// 没有显示
			rlButtom.setVisibility(View.VISIBLE);
			YoYo.with(Techniques.SlideInUp).duration(500).playOn(rlButtom);
		}
	}

	/**
	 * 隐藏工具栏
	 */
	private void hideToolbar() {
		if (rlButtom.getVisibility() == View.VISIBLE) {// 当前在显示
			YoYo.with(Techniques.SlideOutDown).duration(300)
					.withListener(new AnimatorListener() {
						@Override
						public void onAnimationStart(Animator arg0) {
						}

						@Override
						public void onAnimationRepeat(Animator arg0) {
						}

						@Override
						public void onAnimationEnd(Animator arg0) {
							rlButtom.setVisibility(View.GONE);
						}

						@Override
						public void onAnimationCancel(Animator arg0) {
						}
					}).playOn(rlButtom);

		}
	}

	@Bind(R.id.bean_search_lv_parent)
	ListView mFilterParentListView;
	@Bind(R.id.bean_search_lv_china)
	ListView mFilterChildListView;
	@Bind(R.id.beau_filter_view_container)
	RelativeLayout beau_filter_view_container;
	@Bind(R.id.beau_filter_view_container_sub)
	LinearLayout beau_filter_view_container_sub;

	@OnClick(R.id.beau_filter_view_container)
	public void clickFilterContainer() {
		hideSortOrFilter();
	}

	/**
	 * 隐藏
	 */
	private void hideSortOrFilter() {
		// 隐藏
		beau_filter_view_container.setVisibility(View.GONE);
	}

	/**
	 * 显示筛选
	 */
	private void showFilterView() {

		if (!hasFilterViewData()) {
			showNoFilterToast();
			return;
		}

		if (beau_filter_view_container.getVisibility() == View.VISIBLE) {
			hideSortOrFilter();
			return;
		}
		BeauFilterParentAdapter parentAdapter = new BeauFilterParentAdapter(
				mContext);
		mFilterParentListView.setAdapter(parentAdapter);
		parentAdapter.changeData(mFilter.search_filter);
		showChildFilter(mFilter.search_filter.get(0), 0, mFilterChildListView);
		parentAdapter.setmOnIteSelectListener(new OnItemSelectListener() {
			@Override
			public void onSelect(SearchFilter t, int pos) {
				showChildFilter(t, pos, mFilterChildListView);
			}
		});
		beau_filter_view_container.setVisibility(View.VISIBLE);
		beau_filter_view_container.findViewById(R.id.cancel)
				.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						hideSortOrFilter();
					}
				});
		beau_filter_view_container.findViewById(R.id.accept)
				.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						hideSortOrFilter();
						//initRequestData();
					}
				});
	}

	private void showChildFilter(SearchFilter t, int pos, ListView listView) {
		BeauFilterChildAdapter childAdapter = new BeauFilterChildAdapter(
				mContext);
		listView.setAdapter(childAdapter);
		childAdapter.setSelectItem(mFilterSelectArray[pos]);
		childAdapter.changeData(t.values);
		final int pp = pos;
		childAdapter.setmOnSelectItemListener(new OnSelectItemListener() {
			@Override
			public void onSelectItem(int pos, FilterChild t) {
				mFilterSelectArray[pp] = pos;
			}
		});
	}

	@Override
	public void register() {
		EventEngine.register(this);
	}

	@Override
	public void unRegister() {
		EventEngine.uregister(this);
	}

	@Override
	public void onDestroy() {
		unRegister();
		if (mSyncReceiver!=null) {
			mContext.unregisterReceiver(mSyncReceiver);
		}
		super.onDestroy();
	}

	@Override
	public void onClickPhone(int pos, BeauListEntity t) {
		SystemUtils.sendCall(mContext, t.getDianhua());
	}

	@Override
	public void onClickChatter(int pos, BeauListEntity t) {
		enterInfo(t, true);
	}

	@Override
	public void onClickEdit(int pos, BeauListEntity t) {
		Intent intent = new Intent(mContext, CloudWebViewActivity.class);
		intent.putExtra(ExtraConstant.EXTRA_URL,UrlManager.getManager().addReturnUrl(UrlManager.getManager()
				.getEntityDetailEditUrl(t.getId())));
		MonitorParam monitorParam = new MonitorParam(new String[]{"m=save"}, WebSyncDefaultProxy.STEP_START, new String[]{"/WeiXin_index.action"}, true, WebSyncDefaultProxy.STEP_OVERRIDEURL);
		intent.putExtra(
				"callback",
				WebSyncDefaultProxy.creatDefaultProxy(ReceiverConstant.RECEIVE_REFRESH).addMonitorParam(monitorParam).addHomeMonitor());
		startActivity(intent);
	}

	@Override
	public void onClickFollow(final int pos, final BeauListEntity t) {
		new OtherPresenter().followRecord(t.getId(), false,
				new RequestListener() {
					@Override
					public void onSuccess(Object arg0) {
						if(t.ismefollow){
                            Toast.makeText(mContext, "取消追随成功~~", 0).show();
                        }else{
                            Toast.makeText(mContext, "追随成功~~", 0).show();
                        }
						if (mAdapter!=null) {
							boolean ismefollow = mAdapter.getItem(pos).ismefollow;
							 mAdapter.getItem(pos).ismefollow =!ismefollow;
							 mAdapter.notifyDataSetChanged();
						}
					}

					@Override
					public void onFailure(ErrorInfo arg0) {
                        if(t.ismefollow){
                            Toast.makeText(mContext, "取消追随失败~~", 0).show();
                        }else{
                            Toast.makeText(mContext, "追随失败~~", 0).show();
                        }

					}
				});
	}

	@Override
	public void onClickItem(int pos, BeauListEntity t) {
		enterInfo(t, false);
	}

	/**
	 * 进入详情页面
	 * 
	 * @param t
	 * @param siEdit
	 */
	private void enterInfo(BeauListEntity t, boolean siEdit) {
		Intent intent = new Intent(mContext, BeauInfoActivity.class);
		intent.putExtra("beau.name", mEntityName);
		intent.putExtra("beau.nameid", mEntityId);
		intent.putExtra("beau.ismefollow", t.ismefollow);
		intent.putExtra("beau.id", t.getId());
		intent.putExtra("beau.edit", siEdit);
		startActivity(intent);
	}

	/**
	 * 是否有过滤菜单的数据
	 * 
	 * @return
	 */
	private boolean hasFilter() {
		return mFilter != null;
	}

	/**
	 * 是否有 过滤中的 视图菜单数据
	 * 
	 * @return
	 */
	private boolean hasShiTuViewData() {
		return hasFilter() && !ListUtils.isEmpty(mFilter.search_view);
	}

	private void showNoFilterToast() {
		Toast.makeText(mContext, "亲,当前对象没有选择的数据奥 ~~~", 1).show();
	}

	/**
	 * 是否有筛选视图数据
	 * 
	 * @return
	 */
	private boolean hasFilterViewData() {
		return hasFilter() && !ListUtils.isEmpty(mFilter.search_filter);
	}

	/**
	 * 是否有排序视图数据
	 * 
	 * @return
	 */
	private boolean hasSortViewData() {
		return hasFilter() && !ListUtils.isEmpty(mFilter.search_sort);
	}

	public void clickBack(View v) {
		getActivity().finish();
	}

	@Override
	public void onSoftKeyboardShow() {
		rlButtom.setVisibility(View.GONE);
	}

	@Override
	public void onSoftKeyboardHide() {
		InputMethodManager imm = (InputMethodManager) mContext
				.getSystemService(Context.INPUT_METHOD_SERVICE);

		if (getActivity().getWindow().getAttributes().softInputMode == WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
			rlButtom.setVisibility(View.VISIBLE);
		}
		PopuWindowUtils.dissmiss(mSearchView);
	}

	@OnClick(R.id.header_right)
	public void clickNew() {
		Intent intent = new Intent(mContext, CloudWebViewActivity.class);
		intent.putExtra(ExtraConstant.EXTRA_URL, UrlManager.getManager().addReturnUrl(mNewUrl));
		MonitorParam monitorParam = new MonitorParam(new String[]{"m=save"}, WebSyncDefaultProxy.STEP_START, new String[]{"m=query"}, true, WebSyncDefaultProxy.STEP_FINISH);
		intent.putExtra(
				"callback",
				WebSyncDefaultProxy.creatDefaultProxy(ReceiverConstant.RECEIVE_REFRESH).addMonitorParam(monitorParam).addHomeMonitor());
		startActivity(intent);
	}
	private SyncReceiver mSyncReceiver;
	private void initReceiver() {
		mSyncReceiver =new SyncReceiver();
		IntentFilter filter = new IntentFilter();
		filter.addAction(ReceiverConstant.RECEIVE_SYNC_WEB);
		filter.addAction(ReceiverConstant.RECEIVE_REFRESH);
		filter.addAction(ReceiverConstant.RECEIVE_DELETE);
		mContext.registerReceiver(mSyncReceiver, filter);
	}
	
	private class SyncReceiver extends BroadcastReceiver{
		@Override
		public void onReceive(Context context, Intent intent) {
			mListView.requestRefresh();
		}
	}

	@Override
	public void onRefresh(PtrFrameLayout frame) {
		refresh();
	}



	@Override
	public void onLoadMore(LoadMoreContainer frame) {
		currentPage++;
		requestData();
	}
}
